const mqtt = require('mqtt')

let deviceCode = "B49E800EBBE9"

let username = "admin"
let password = "nttieren0513"

// iot生产环境
let connectUrl = 'wss://iot.ironmanapi.com:8084/mqtt'
// iot测试环境
// connectUrl = 'wss://test.ironmanapi.com:8084/mqtt'

const clientId = `chj_test_${Math.floor(Math.random() * 100) + 1}`

// 连接选项
const options = {
    clean: true, // true: 清除会话, false: 保留会话
    connectTimeout: 15000, // 超时时间
    clientId,
    username,
    password,
    keepalive: 5,
    will: {
        topic: `will-msg/${clientId}`,
        payload: 'offline',
        qos: 2,
        retain: false
    }
}

const client = mqtt.connect(connectUrl, options)

module.exports = {
    connectUrl,
    client,
    deviceCode
}
